package com.gpframework.module.purchase.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.purchase.domain.GpPurchaseTrack;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName GpPurchaseTrackReq
 * @Author gpframework
 * @Date 2023-12-22
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpPurchaseTrackReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("缺货报库存申请表id")
     private Long productionApplicationId;
     @ApiModelProperty("做货明细表id")
     private Long purchasingDetailsId;
     @ApiModelProperty("排单表id")
     private Long procureSchedulingId;
     @ApiModelProperty("到货单id")
     private Long purchaseReceiptId;
     @ApiModelProperty("跟踪单号")
     private String sn;
     @ApiModelProperty("批号")
     private String batchNo;
     @ApiModelProperty("供应商")
     private String supplier;
     @ApiModelProperty("发货日期")
     private Date sendTime;
     @ApiModelProperty("仓点")
     private String storePoint;
     @ApiModelProperty("品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String productColor;
     @ApiModelProperty("成本")
     private BigDecimal cost;
     @ApiModelProperty("胚布单价")
     private BigDecimal fabricPrice;
     @ApiModelProperty("染费单价")
     private BigDecimal dyeingPrice;
     @ApiModelProperty("染厂")
     private String dyeingFactory;
     @ApiModelProperty("染厂进仓数量")
     private Long dyeingIntoNum;
     @ApiModelProperty("成品条数")
     private Long productsNum;
     @ApiModelProperty("打码规格（足码）")
     private String codingSpecificationsSufficient;
     @ApiModelProperty("打码规格（空码）")
     private String codingSpecificationsEmpty;
     @ApiModelProperty("大小条（码）")
     private Integer sizeBar;
     @ApiModelProperty("成品总码数（足）")
     private BigDecimal finishProductQuantitySufficient;
     @ApiModelProperty("成品入库总码数（空）")
     private BigDecimal finishProductQuantityEmpty;
     @ApiModelProperty("单条重量KG")
     private BigDecimal singleWeight;
     @ApiModelProperty("成品净重KG")
     private BigDecimal finishProductWeight;
     @ApiModelProperty("纸管重量KG")
     private BigDecimal paperTubeWeight;
     @ApiModelProperty("损耗KG")
     private BigDecimal lossWeight;
     @ApiModelProperty("损耗率")
     private BigDecimal lossRate;
     @ApiModelProperty("正常损耗值")
     private BigDecimal normalLossValue;
     @ApiModelProperty("损耗差异")
     private BigDecimal lossDiff;
     @ApiModelProperty("胚布出码率（码/KG）")
     private BigDecimal greyClothOutputRate;
     @ApiModelProperty("成品出码率（码/KG）")
     private BigDecimal finishProductOutputRate;
     @ApiModelProperty("标准出码率（码/KG）")
     private BigDecimal standardOutputRate;
     @ApiModelProperty("出码差异")
     private BigDecimal outputDiff;
     @ApiModelProperty("备注")
     private String remarks;
     @ApiModelProperty("订单状态")
     private String orderState;
     @ApiModelProperty("订单二维码")
     private String orderQrCode;
     @ApiModelProperty("操作人id")
     private Long merchandiserId;
     @ApiModelProperty("操作人")
     private String merchandiser;
     @ApiModelProperty("操作时间")
     private Date operatorTime;
     @ApiModelProperty("关联收货单号")
     private String relatedReceiveNumber;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpPurchaseTrack> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias + "create_time");
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (this.getProductionApplicationId() != null){
        lqw.eq(alias+"production_application_id" ,this.getProductionApplicationId());
        }
        if (this.getPurchasingDetailsId() != null){
        lqw.eq(alias+"purchasing_details_id" ,this.getPurchasingDetailsId());
        }
        if (this.getProcureSchedulingId() != null){
        lqw.eq(alias+"procure_scheduling_id" ,this.getProcureSchedulingId());
        }
        if (this.getPurchaseReceiptId() != null){
        lqw.eq(alias+"purchase_receipt_id" ,this.getPurchaseReceiptId());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.like(alias+"sn" ,this.getSn());
        }
        if (StringUtils.isNotBlank(this.getBatchNo())){
        lqw.like(alias+"batch_no" ,this.getBatchNo());
        }
        if (StringUtils.isNotBlank(this.getSupplier())){
        lqw.like(alias+"supplier" ,this.getSupplier());
        }
        if (this.getSendTime() != null){
        lqw.eq(alias+"send_time" ,this.getSendTime());
        }
        if (StringUtils.isNotBlank(this.getStorePoint())){
        lqw.eq(alias+"store_point" ,this.getStorePoint());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getProductColor())){
        lqw.like(alias+"product_color" ,this.getProductColor());
        }
        if (this.getCost() != null){
        lqw.eq(alias+"cost" ,this.getCost());
        }
        if (this.getFabricPrice() != null){
        lqw.eq(alias+"fabric_price" ,this.getFabricPrice());
        }
        if (this.getDyeingPrice() != null){
        lqw.eq(alias+"dyeing_price" ,this.getDyeingPrice());
        }
        if (StringUtils.isNotBlank(this.getDyeingFactory())){
        lqw.eq(alias+"dyeing_factory" ,this.getDyeingFactory());
        }
        if (this.getDyeingIntoNum() != null){
        lqw.eq(alias+"dyeing_into_num" ,this.getDyeingIntoNum());
        }
        if (this.getProductsNum() != null){
        lqw.eq(alias+"products_num" ,this.getProductsNum());
        }
        if (StringUtils.isNotBlank(this.getCodingSpecificationsSufficient())){
        lqw.eq(alias+"coding_specifications_sufficient" ,this.getCodingSpecificationsSufficient());
        }
        if (StringUtils.isNotBlank(this.getCodingSpecificationsEmpty())){
        lqw.eq(alias+"coding_specifications_empty" ,this.getCodingSpecificationsEmpty());
        }
        if (this.getSizeBar() != null){
        lqw.eq(alias+"size_bar" ,this.getSizeBar());
        }
        if (this.getFinishProductQuantitySufficient() != null){
        lqw.eq(alias+"finish_product_quantity_sufficient" ,this.getFinishProductQuantitySufficient());
        }
        if (this.getFinishProductQuantityEmpty() != null){
        lqw.eq(alias+"finish_product_quantity_empty" ,this.getFinishProductQuantityEmpty());
        }
        if (this.getSingleWeight() != null){
        lqw.eq(alias+"single_weight" ,this.getSingleWeight());
        }
        if (this.getFinishProductWeight() != null){
        lqw.eq(alias+"finish_product_weight" ,this.getFinishProductWeight());
        }
        if (this.getPaperTubeWeight() != null){
        lqw.eq(alias+"paper_tube_weight" ,this.getPaperTubeWeight());
        }
        if (this.getLossWeight() != null){
        lqw.eq(alias+"loss_weight" ,this.getLossWeight());
        }
        if (this.getLossRate() != null){
        lqw.eq(alias+"loss_rate" ,this.getLossRate());
        }
        if (this.getNormalLossValue() != null){
        lqw.eq(alias+"normal_loss_value" ,this.getNormalLossValue());
        }
        if (this.getLossDiff() != null){
        lqw.eq(alias+"loss_diff" ,this.getLossDiff());
        }
        if (this.getGreyClothOutputRate() != null){
        lqw.eq(alias+"grey_cloth_output_rate" ,this.getGreyClothOutputRate());
        }
        if (this.getFinishProductOutputRate() != null){
        lqw.eq(alias+"finish_product_output_rate" ,this.getFinishProductOutputRate());
        }
        if (this.getStandardOutputRate() != null){
        lqw.eq(alias+"standard_output_rate" ,this.getStandardOutputRate());
        }
        if (this.getOutputDiff() != null){
        lqw.eq(alias+"output_diff" ,this.getOutputDiff());
        }
        if (StringUtils.isNotBlank(this.getRemarks())){
        lqw.eq(alias+"remarks" ,this.getRemarks());
        }
        if (StringUtils.isNotBlank(this.getOrderState())){
        lqw.eq(alias+"order_state" ,this.getOrderState());
        }
        if (StringUtils.isNotBlank(this.getOrderQrCode())){
        lqw.eq(alias+"order_qr_code" ,this.getOrderQrCode());
        }
        if (this.getMerchandiserId() != null){
        lqw.eq(alias+"merchandiser_id" ,this.getMerchandiserId());
        }
        if (StringUtils.isNotBlank(this.getMerchandiser())){
        lqw.eq(alias+"merchandiser" ,this.getMerchandiser());
        }
        if (this.getOperatorTime() != null){
        lqw.eq(alias+"operator_time" ,this.getOperatorTime());
        }
        if (StringUtils.isNotBlank(this.getRelatedReceiveNumber())){
        lqw.eq(alias+"related_receive_number" ,this.getRelatedReceiveNumber());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.product_color", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
